home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Developer's Companion
/
Java Developer's Companion.iso
/
Javacup
/
IN231VFD.TAR
/
internet
/
IN231VFD
/
CameraView.java
< prev
next >
Wrap
Text File
|
1996-05-21
|
2KB
|
83 lines
// CameraView.java - Pop up picture of a single view within a house
//
// Copyright (C) 1996 by Dale Gass
// Non-exclusive license granted to MKS, Inc.
//
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.net.*;
import java.applet.*;
import java.awt.image.*;
// CameraView - The frame which pops up a photo
public class CameraView extends Frame implements ImageObserver {
Image pic;
boolean loaded;
Applet app;
int w, h;
// Watch the loading of the images; resize/repaint when done
public boolean imageUpdate(Image img, int infoflags,
int x, int y, int width, int height) {
if ((infoflags & ALLBITS) != 0) {
loaded = true;
resize(w = pic.getWidth(app), h = pic.getHeight(app));
repaint();
return false;
}
return true;
}
// Constructor; given a house, floor plan, and camera number, and
// on-screen camera object (for the description), load and display
// the view.
public CameraView(Applet a, House house, int floor, int camnum,
Camera camera) {
super(camera.describe);
app = a;
pic = app.getImage(app.getCodeBase(),
house.getCode()+floor+camnum+".gif");
w = pic.getWidth(this);
h = pic.getHeight(this);
setFont(new Font("Helvetica", Font.BOLD, 18));
show();
if (w == -1 || h == -1) {
loaded = false;
resize(300, 100);
} else {
loaded = true;
resize(w, h);
}
}
// Update the image (or status if still loading)
public void paint(Graphics g) {
g.drawImage(pic, 0, 0, this);
if (!loaded)
g.drawString("Loading...", 80, 40);
}
// Override update() method to avoid painting to background colour;
// reduces flicker (well, it should; Netscape still does too much
// redrawing :-)
public void update(Graphics g) {
paint(g);
}
// Handle window destruction
public boolean handleEvent(Event evt) {
if (evt.id == Event.WINDOW_DESTROY)
dispose();
return (false);
}
}